<?php
namespace app\admin\controller;
use think\Controller;
/**
* 前台登录
*/
class Menoy extends Controller
{
	
	public function admin_list(){
		$menoy = db('menoy');
		if(empty($_POST['kaishi']) && empty($_POST['jieshu']) && empty($_POST['tiaojian'])){
          $todayend = strtotime(date('Y-m-d'.'00:00:00',time()));//条件最早时间
          $todaystart = strtotime(date('Y-m-d'.'23:59:59',time()));//条件最晚时间
          $where = "shijian >= ".$todayend." and shijian <= ".$todaystart.""; 
		}else if(!empty($_POST['tiaojian']) && !empty($_POST['kaishi']) && !empty($_POST['jieshu'])){	
                  $todayend = strtotime(input('kaishi').'00:00:00');//开始时间
				$todaystart = input('jieshu');//结束时间
				$todaystart = strtotime(date("".$todaystart."".'23:59:59' , time()));
                  $tiaojian = $_POST['tiaojian'];
                  $where = "shijian >= ".$todayend." and shijian <= ".$todaystart." and out_trade_no = ".$tiaojian.""; 
		}else if(!empty($_POST['tiaojian']) && empty($_POST['kaishi']) && empty($_POST['jieshu'])){
			$tiaojian = $_POST['tiaojian'];
				$where = "out_trade_no = ".$tiaojian.""; 
			
		}else if(!empty($_POST['kaishi']) && !empty($_POST['jieshu']) && empty($_POST['tiaojian'])){
		$todayend = strtotime(input('kaishi').'00:00:00');//开始时间
		$todaystart = input('jieshu');//结束时间
		$todaystart = strtotime(date("".$todaystart."".'23:59:59' , time()));
		  $where = "shijian >= ".$todayend." and shijian <= ".$todaystart."";
		}
	
        $field = 'id,mch_id,total_fee,body,status_jy,sub_openid,out_trade_no,shijian,buyer_id';
		$sele = $menoy->field($field)->where($where)->order('id desc')->select();

		foreach($sele as $k=>$v){
           $sele[$k]['total_fee'] = (int)$v['total_fee'] / (int)100;
           $sele[$k]['shijian'] = date("Y-m-d H:i:s",$v['shijian']);
		}
        $this->assign('menoy',$sele);
        	//-------------------------
		//查询今日总交易-----------------------------------------
		 $kai = strtotime(date('Y-m-d'.'00:00:00',time()));//条件最早时间
         $jie = strtotime(date('Y-m-d'.'23:59:59',time()));//条件最晚时间
         $whe = "shijian >= ".$kai." and shijian <= ".$jie." and status_jy = 0"; 
		$condd = $menoy->field("sum(total_fee)")->where($whe)->order('id desc')->find(); 

		$condc = $menoy->field("id")->where($whe)->order('id desc')->count(); 
		$jin = $condd['sum(total_fee)'];
		$jin = (int)$jin / (int)100;
		$jintian['total_fee'] = $jin;
		$jintian['count'] = $condc;
		$this->assign('jintian',$jintian);
		//var_dump(getdate()).'1321321';
		//查询全部交易额度-------------------------------------
  
		$concc = $menoy->field("sum(total_fee)")->where("status_jy = 0")->order('id desc')->find(); 
		$zong = $concc['sum(total_fee)'];
		$zong = (int)$zong / (int)100;
        $this->assign('zongjine',$zong);

        //查询总订单数
		$coun = $menoy->field("id")->where("status_jy = 0")->order('id desc')->count(); 
		$this->assign('zongtiaoshu',$coun);
        //查询七天前总金额-----------------------------------------------------
        $kaiq = strtotime(date('Y-m-d'.'00:00:00',time()-3600*144));//条件最早时间
        $jieq = strtotime(date('Y-m-d'.'23:59:59',time()));//条件最晚时间
        $wheq = "shijian >= ".$kaiq." and shijian <= ".$jieq." and status_jy = 0" ; 
        $qitian_fee = $menoy->field("sum(total_fee)")->where($wheq)->order('id desc')->find(); 

        $qitian_con = $menoy->field("id")->where($wheq)->order('id desc')->count(); 
        $qitian_fee = $qitian_fee['sum(total_fee)'];
		$qitian_fee = (int)$qitian_fee / (int)100;

	    $qitian['qitian_fee'] = $qitian_fee;
	    $qitian['qitian_con'] = $qitian_con;
        //-------------------------------------------------------------

	    $this->assign('qitian',$qitian);
	
        
		return view();
	}

	
	
	
}